package com.laborder.sysyy.service.log.impl;
import com.laborder.sysyy.dao.LogDaoMapper;
import com.laborder.sysyy.entity.LogEntity;
import com.laborder.sysyy.service.log.LogService;
import com.laborder.sysyy.utils.getIp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Function: 日志业务实现层
 * @author: 786107529@qq.com FJL
 * @date:2018/10/10 14:03
 */
@Service
@Transactional
public class LogServiceImpl implements LogService {
	
	@Autowired
	private LogDaoMapper logDaoMapper;
	@Override
	public void save(String userName,String operation, HttpServletRequest request){
		LogEntity entity = new LogEntity();
		entity.setLogId(UUID.randomUUID().toString());
		entity.setUserName(userName);
		entity.setOperation(operation);
		entity.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		String ip=getIp.getClientIp(request);
		entity.setIp(ip);
		logDaoMapper.save(entity);
	}

	/*
	分页查询
	 */
	@Override
	public List<LogEntity> findLogWithPage(Map<String,Object> map){
		return logDaoMapper.findLogWithPage(map);
	}
	/*
	 查询数量
	 */
	@Override
	public int getLogCount(Map<String,Object> map){
		return logDaoMapper.getLogCount(map);
	}
	
}
